package org.yzz.base.util;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.yzz.org.domain.Employee;
import org.yzz.org.domain.Shop;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Map;

@Component
public class EmailUtil {

    @Autowired
    private  JavaMailSender javaMailSender;

    public void  simpleMailSend(){
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("1185025898@qq.com");
        //邮件主题
        mailMessage.setSubject("这是一封来自远古的邮件..");
        //邮件内容
        mailMessage.setText("海绵布布，我们去抓水母呀");
        //收件人
        mailMessage.setTo("1678616375@qq.com");

        javaMailSender.send(mailMessage);
    }

    /**
     * 需要 商品管理员的 id 、邮箱
     */
    public void mimeMailSend(String title,String aText,String address) throws Exception{
        //创建复杂邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //发送复杂邮件的工具类
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
        helper.setFrom("1185025898@qq.com");
        helper.setSubject(title);
        helper.setText(aText,true);
        //收件人
        helper.setTo(address);
        javaMailSender.send(mimeMessage);
    }
}
